﻿using Sustainalytics.Entities;
using System.Linq;

namespace Sustainalytics.DataLayer
{
    public static class EventsExtensions
    {
        public static IQueryable<Event> Filter(this IQueryable<Event> query, EventsFilter filter)
        {
            if (string.IsNullOrEmpty(filter.SearchText) == false)
            {
                string term = filter.SearchText.ToLower();

                // filter title
                query = query.Where(el => el.Name.ToLower().Contains(term));
            }

            if (filter.Sponsorship)
            {
                // filter by type
                query = query.Where(el => el.Sponsorship == filter.Sponsorship);
            }

            return query;
        }
    }
}
